<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>player</title>
  
  <script>
    var list = ["像我这样的人.mp3", "十年.mp3"];
    var currentIndex = 0;
    // 点击暂停播放事件
    function play() {
      var player = document.getElementById("player");
      if(player.paused) {
        player.play();
      } else {
        player.pause();
      }
    }

    function prev() {
      var player = document.getElementById("player");
      if(currentIndex == 0) {
        currentIndex = list.length - 1;
       
      } else {
        currentIndex -= 1;
      }
      player.src = list[currentIndex];
      player.load();
      play();
    }

    function next() {
      var player = document.getElementById("player");
      if(currentIndex == list.length-1) {
        currentIndex = 0;
       
      } else {
        currentIndex += 1;
      }
      player.src = list[currentIndex];
      player.load();
      play();
    }

  </script>
  <style>
    body {
      text-align: center;
    }
    .header {
      padding-top: 50px;
      padding-bottom: 20px;
    }
  </style>
</head>
<body>
  <div class="header">
    <h2>this is a player</h2>
    <img src="./img/logo.png" />
  </div>
  
  <div>
    <audio controls id="player" src="./像我这样的人.mp3"></audio><br>
    <button onclick="play()">暂停/播放</button>
    <button onclick="prev()">上一首</button>
    <button onclick="next()">下一首</button>
  </div>
</body>
</html>
